/* part2test.c
 * test the fork,exec syscall
 */
#include "utility.h"
int f1t1overlock, f1t1overcv;
int e1t1overlock, e1t1overcv;

void f1T1f1(){
    Printf("f1T1 function 1, fork the right function\n");
    AcquireLock(f1t1overlock);
    SignalCV(f1t1overlock, f1t1overcv);
    ReleaseLock(f1t1overlock);
    Exit(0);
}

void f1T1(){
    f1t1overlock=CreateLock("f1t1overlock", 12);
    f1t1overcv=CreateCV("f1t1overcv", 12);
    Printf("f1T1 fork  f1T1f1 function, a correct function\n");
    Fork(f1T1f1);
    AcquireLock(f1t1overlock);
    WaitCV(f1t1overlock, f1t1overcv);
    ReleaseLock(f1t1overlock);
}

void f1T2(){
    int i=0;
    Printf("f1T2 fork a zero address\n");
    Fork(i);
}

void e1T1(){
    Printf("e1T1 runs the ../test/execsample file\n");
    Exec("../test/execsample",25);
    Yield();
}
void e1T2(){
    Printf("e1T2 runs a non-existed file\n");
    Exec("../test/nonexist",19);
}


void e1T3(){
    Printf("e1T3 runs the ../test/execsample.c file, it could not run in nachos\n");
    Exec("../test/halt.c",19);
}




int main()
{
    f1T1();
    f1T2();

    e1T1();
   e1T2();
    e1T3();

    Exit(0);
}

